package com.MC.MCard.servlet;

import com.MC.MCard.dao.MerchantDao;
import com.MC.MCard.dao.MerchantDaoImpl;
import com.MC.MCard.entity.Merchant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.text.View;
import java.io.IOException;

@WebServlet("/login")
public class MerchantloginServlet extends HttpServlet {
    private MerchantDaoImpl merchantDao =  new MerchantDaoImpl();

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String memail = req.getParameter("memail");
        String mpassword = req.getParameter("mpassword");
        System.out.println("memail:" + memail);
        System.out.println("mpassword:" + mpassword);

        Merchant merchant = merchantDao.findByEmail(memail);


        if( merchant != null && mpassword.equals( merchant.getMpassword())) {
            resp.sendRedirect("index.jsp");
        } else {
            resp.sendRedirect("login.jsp?code=500");
        }
    }

}
